package com.ruoyi.statisticalCenter.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.InitTableVo;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.statisticalCenter.domain.ScQualityControlFeeSheet;
import com.ruoyi.statisticalCenter.domain.vo.ScQualityControlFeeSheetVo;
import com.ruoyi.statisticalCenter.mapper.ScQualityControlFeeSheetMapper;
import com.ruoyi.statisticalCenter.service.ScQualityControlFeeSheetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ScQualityControlFeeSheetServiceImpl implements ScQualityControlFeeSheetService {
    @Autowired
    private ScQualityControlFeeSheetMapper scQualityControlFeeSheetMapper;
    @Autowired
    private TableService tableService;

    @Override
    public R collect(ScQualityControlFeeSheetVo vo) {
        PageHelper.startPage(vo.getPageDate());
        List<ScQualityControlFeeSheet> collect = scQualityControlFeeSheetMapper.collect(vo);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list", PageInfo.info(collect));
        jsonObject.put("fields", getTableVo());

        if (collect == null || collect.size() == 0) {
            return R.ok("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }
    public List<TableVo> getTableVo() {
        List<TableVo> first = new ArrayList<>();
        TableVo firstTableVo = new TableVo();firstTableVo.setFields("name");firstTableVo.setTranslate("承包区名称");first.add(firstTableVo);
        firstTableVo = new TableVo();firstTableVo.setFields("inboundTickets");firstTableVo.setTranslate("进港票数");first.add(firstTableVo);
        firstTableVo = new TableVo();firstTableVo.setFields("outboundTickets");firstTableVo.setTranslate("出港票数");first.add(firstTableVo);
        firstTableVo = new TableVo();firstTableVo.setFields("threeReturn");firstTableVo.setTranslate("三件返款");
        List<TableVo> second = new ArrayList<>();

        TableVo secondTableVo = new TableVo();secondTableVo.setFields("headToMe");secondTableVo.setTranslate("出港理赔总部给公司");
        List<TableVo> third = new ArrayList<>();
        String[] headToMe = {"outboundThreePiecesDelay", "outboundThreePiecesLost", "outboundThreePiecesDamaged", "outboundThreeReturnMoney","outboundThreePiecesTotal","outboundThreePiecesSingleReceipt"};
        InitTableVo initTableVo = new InitTableVo();
        initTableVo.setFields(headToMe);
        initTableVo.setCode("scQuality");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();secondTableVo.setFields("meToArea");secondTableVo.setTranslate("出港理赔公司给承包区");
        third = new ArrayList<>();
        String[] meToArea = {"toContractAreaDelay", "toContractAreaLost", "toContractAreaDamaged", "toContractAreaThreeReturnMoney","toContractAreaTotal","toContractAreaSingleReceipt","toContractAreaProfitLoss"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(meToArea);
        initTableVo.setCode("scQuality");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);
        firstTableVo.setSunList(second);
        first.add(firstTableVo);

        firstTableVo = new TableVo();firstTableVo.setFields("threePay");firstTableVo.setTranslate("三件赔款");
        secondTableVo = new TableVo();secondTableVo.setFields("inboundToHead");secondTableVo.setTranslate("进港三件理赔公司赔总部");
        third = new ArrayList<>();
        String[] inboundToHead = {"inboundThreePiecesPenaltyDelay", "inboundThreePiecesPenaltyLost", "inboundThreePiecesPenaltyDamaged", "inboundThreePiecesPenaltyOverDispatchFee","inboundThreePiecesThreeIndemnity","inboundThreePiecesPenaltyTotal","inboundThreePiecesPenaltyFinePerTicket"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(inboundToHead);
        initTableVo.setCode("scQuality");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();secondTableVo.setFields("inboundToMe");secondTableVo.setTranslate("进港三件理赔承包区赔公司");
        third = new ArrayList<>();
        String[] inboundToMe = {"penaltyToContractAreaDelay", "penaltyToContractAreaLost", "penaltyToContractAreaDamaged", "penaltyToContractAreaThreeIndemnity","penaltyToContractAreaTotal","penaltyToContractAreaFinePerTicket","threeIndemnity"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(inboundToMe);
        initTableVo.setCode("scQuality");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);
        firstTableVo.setSunList(second);
        first.add(firstTableVo);

        firstTableVo = new TableVo();firstTableVo.setFields("system");firstTableVo.setTranslate("系统扣款、罚款、赔款");
        second = new ArrayList<>();
        String[] system = {"priorClaim", "falseIssueAssessment", "falseSignatureAssessment", "inadequateSignatureRateAssessment","automaticTicketAssessment","ticketServiceQualityAssessment","phoneServiceQualityAssessment"
                ,"peersPackagingAssessment","branchViolationsAssessment","terminalAssessment","networkManagementComprehensiveCharge","networkManagementComprehensivePayment","vehicleAssessment","environmentallyFriendlyBagOvertimeCharge"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(system);
        initTableVo.setCode("scQuality");
        second = tableService.initTable(initTableVo);
        firstTableVo.setSunList(second);
        first.add(firstTableVo);


        firstTableVo = new TableVo();firstTableVo.setFields("market");firstTableVo.setTranslate("市场部业务");
        second = new ArrayList<>();
        String[] market = {"headquartersMajorCustomers", "scatteredBusinessSettlement", "scatteredSinglePerformanceAssessment", "marketCustomerServiceCharge","CODBusiness","CODPayment","CODPaymentFee","internationalBusinessFee","tikTokProject","insuranceFee"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(market);
        initTableVo.setCode("scQuality");
        second = tableService.initTable(initTableVo);
        firstTableVo.setSunList(second);
        first.add(firstTableVo);

        firstTableVo = new TableVo();firstTableVo.setFields("fee");firstTableVo.setTranslate("综合费用");
        second = new ArrayList<>();
        String[] fee = {"hostingServiceFee", "onlineCustomerServiceFee", "callSystemMonthlyRent", "phoneAnsweringServiceFee","SMSReminderBusiness","phoneCommunicationFee","handlingFee","wovenBagFee","branchUtilitiesFee"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(fee);
        initTableVo.setCode("scQuality");
        second = tableService.initTable(initTableVo);
        firstTableVo.setSunList(second);
        first.add(firstTableVo);

        return first;
    }
}
